package com.ct.deadlockdetetor.common.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.ct.deadlockdetetor.common.pojo.CommonResult;
import com.ct.deadlockdetetor.common.pojo.TableDataInfo;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class BaseController {

    public CommonResult<Void> toCommonResult(int rows) {
        return rows > 0 ? CommonResult.ok() : CommonResult.fail();
    }

    public CommonResult<Void> toCommonResult(boolean result) {
        return result ? CommonResult.ok() : CommonResult.fail();
    }

    public TableDataInfo getTableDataInfo(List<?> list) {

        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        long total = new PageInfo<>(list).getTotal();
        return TableDataInfo.success(list, total);
    }
}